//app.js
import { ifLogined } from './utils/util.js'
App({
  globalData: {
    systeminfo: {},
    userInfo: {},
    config: {
      loginRequestUrl: 'https://juejin.im/auth/type/phoneNumber',
      notifyRequestUrl: 'https://ufp-api-ms.juejin.im/v1',
      bannerRequestUrl: 'https://banner-storage-ms.juejin.im/v1',
      timelineRequestUrl: 'https://timeline-merger-ms.juejin.im/v1',
      xiaoceRequestUrl: 'https://xiaoce-timeline-api-ms.juejin.im/v1',
      xiaoceCacheApiMs: 'https://xiaoce-cache-api-ms.juejin.im/v1',
      postStorageApiMsRequestUrl: 'https://post-storage-api-ms.juejin.im/v1',
      userLikeWrapperMsRequestUrl: 'https://user-like-wrapper-ms.juejin.im/v1',
      // searchMergerMsRequestUrl: 'https://search-merger-ms.juejin.im/v1',
      collectionSetMsRequestUrl: 'https://collection-set-ms.juejin.im/v1',
      shortMsgMsRequestUrl: 'https://short-msg-ms.juejin.im/v1',
      ufpApiMsRequestUrl: 'https://ufp-api-ms.juejin.im/v1',
      lccroApiMsRequestUrl: 'https://lccro-api-ms.juejin.im/v1',
      entryViewStorageApiMsRequestUrl: 'https://entry-view-storage-api-ms.juejin.im/v1',
      goldTagMsRequestUrl: 'https://gold-tag-ms.juejin.im/v1',
      userNotificationApiMsRequestUrl: 'https://user-notification-api-ms.juejin.im/v1',
      apiRequestUrl: 'https://user-storage-api-ms.juejin.im/v1'
    }
  },
  onLaunch() {
    wx.getSystemInfo({
      success: res => {
        this.globalData.systeminfo = res
      },
    })

    this.getUserInfo()
  },
  // 获取用户信息
  getUserInfo() {
    let auth = ifLogined()
    wx.request({
      url: `${this.globalData.config.apiRequestUrl}/getUserInfo`,
      data: {
        src: 'web',
        device_id: auth.clientId,
        uid: auth.uid,
        token: auth.token,
        current_uid: auth.uid,
      },
      success: res => {
        let data = res.data
        if (data.s === 1) {
          this.globalData.userInfo = data.d
        } else {
          wx.showToast({
            title: data.m.toString(),
            icon: 'none',
          })
        }
      },
      fail: err => {
        wx.showToast({
          title: err,
          icon: 'none',
        })
      },
    })
  }
})